public class demo12 {
    public static void main(String[] args) throws InterruptedException {
        Object locker1 = new Object();
        Object locker2 = new Object();
        Object locker3 = new Object();
        Thread a = new Thread(()-> {
               try {
                   synchronized (locker3) {
                       locker3.wait();
                   }
                   System.out.println("a");
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
        });
        Thread b = new Thread(()-> {
            try {
                synchronized (locker2) {
                    locker2.wait();
                }
                System.out.print("b");
                synchronized (locker3) {
                    locker3.notify();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        Thread c = new Thread(()-> {
            try {
                synchronized (locker1) {
                    locker1.wait();
                }
                System.out.print("c");
                synchronized(locker2) {
                    locker2.notify();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        a.start();
        b.start();
        c.start();
        Thread.sleep(1000);
        synchronized (locker1) {
            locker1.notify();
        }
    }
}
